<?php
namespace Home\Controller;
class IndexController extends HomeController {
	public function _initialize() {
        parent::_initialize();
    }
    public function index(){
        $News = D('Article');

        $top_active = D('Attr')->relation('top_active')->find(2);

        //幻灯新闻 后台设置属性推荐
        $flash_news = D('Attr')->relation('article')->find(2);
        $map['status'] = 1;

        //新闻列表
        $cate_id = 1;
        if ($cate_id) {
            $id_arr = D('ArticleCate')->get_child_ids($cate_id, true);
            $map['cate_id'] = array('IN', $id_arr);
        }
        $news = D('Article')->field('id,title,intro,img')->where($map)->order('ordid desc,add_time desc')->limit(20)->select();

        //夏令营
        $cate_id = 16;
        $camp = D('ArticleCate')->where(array('pid'=>$cate_id))->limit(3)->order('ordid desc,id desc')->select();
		
		//合作院校
        $map['cate_id'] = array('eq',24);
        $school = D('Article')->field('id,title,img')->where(array('cate_id'=>24))->order('ordid desc,add_time desc')->limit(11)->select();

        //模板赋值
		$this->assign('apply_city_list',C('apply_city_list'));
		$this->assign('apply_age_list',C('apply_age_list'));

        $this->assign('news',$news);
        $this->assign('top_active',$top_active['top_active']);
		$this->assign('school',$school);
        $this->assign('camp',$camp);

		$this->display();
    }
	public function apply(){
		if(IS_AJAX){
			$data = I('post.');
            empty($data['username']) && $this->error('姓名不能为空');
            empty($data['age']) && $this->error('年龄不能为空');
            (!check_mobile($data['mobile'])) && $this->error('手机号码格式有误');
            (!check_email($data['email'])) && $this->error('邮箱格式有误');
			$apply = D('Apply');
			$data = $apply->create($data);
			if (!$data){
				$this->error($apply->getError());
			}else{
				$apply->add($data);
                $this->success('申请成功！');
			}
		}
	}
	public function get_video(){
		if(IS_AJAX){
			$video = '<embed src="http://static.youku.com/v/swf/qplayer.swf?VideoIDS=XOTUzOTkzMjAw&isAutoPlay=true&showAd=0" allowfullscreen="true" quality="high" width="1000" height="605" align="middle" allowscriptaccess="always" type="application/x-shockwave-flash">';
			echo json_encode($video);
		}
	}
}